//
//  NewsTableViewCell.m
//  PrayerTimes
//
//  Created by Igor Karpenko on 6/10/13.
//  Copyright (c) 2013 Igor Karpenko. All rights reserved.
//

#import "NewsTableViewCell.h"

@implementation NewsTableViewCell

-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (!self) {
        return nil;
    }
	
	_iconImage = [[UIImageView alloc] init];
	_iconImage.backgroundColor = [UIColor whiteColor];
	[self addSubview:_iconImage];
	
	_userNameLabel = [[UILabel alloc] init];
	_userNameLabel.textColor = RGB(70.0f, 70.0f, 70.0f);
	_userNameLabel.shadowColor = [UIColor whiteColor];
	_userNameLabel.shadowOffset = CGSizeMake(1.0f, 1.0f);
	_userNameLabel.font = [UIFont fontWithName:@"Verdana-Bold"
										  size:14.0f];
	_userNameLabel.backgroundColor = [UIColor clearColor];
	[self addSubview:_userNameLabel];
	
	_dateLabel = [[UILabel alloc] init];
	_dateLabel.textColor = RGB(70.0f, 70.0f, 70.0f);
	_dateLabel.shadowColor = [UIColor whiteColor];
	_dateLabel.shadowOffset = CGSizeMake(1.0f, 1.0f);
	_dateLabel.font = [UIFont fontWithName:@"Verdana"
										  size:14.0f];
	_dateLabel.backgroundColor = [UIColor clearColor];
	_dateLabel.textAlignment = NSTextAlignmentRight;
	[self addSubview:_dateLabel];
	
	_tweetLabel = [[UILabel alloc] init];
	_tweetLabel.textColor = RGB(70.0f, 70.0f, 70.0f);
	_tweetLabel.shadowColor = [UIColor whiteColor];
	_tweetLabel.shadowOffset = CGSizeMake(1.0f, 1.0f);
	_tweetLabel.font = [UIFont fontWithName:@"Verdana"
									  size:14.0f];
	_tweetLabel.backgroundColor = [UIColor clearColor];
	_tweetLabel.numberOfLines = 0;
	[self addSubview:_tweetLabel];
	
	_lineView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nws_separator"]];
	_lineView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
	[self addSubview:_lineView];
	
	return self;
}


-(void) dealloc {
	[_iconImage release];
	[_userNameLabel release];
	[_dateLabel release];
	[_tweetLabel release];
	[_lineView release];
	
	[super dealloc];
}


-(void) layoutSubviews {
	[super layoutSubviews];
	float padding = 10.0f;
	float screenWidth = self.frame.size.width;
	
	CGRect newFrame = CGRectMake(padding, padding, 50.0f, 50.0f);
	_iconImage.frame = newFrame;
	
	newFrame.origin.x += newFrame.size.width + padding;
	newFrame.size.width = 120.0f;
	newFrame.size.height = 20.0f;
	_userNameLabel.frame = newFrame;
	
	newFrame.origin.x = screenWidth - newFrame.size.width - padding;
	_dateLabel.frame = newFrame;
	
	newFrame.origin.x = _userNameLabel.frame.origin.x;
	newFrame.origin.y = _dateLabel.frame.origin.y + _dateLabel.frame.size.height;
	newFrame.size.width = screenWidth - newFrame.origin.x - padding;
	CGSize textSize = [_tweetLabel.text sizeWithFont:[UIFont fontWithName:@"Verdana" size:14.0f]
								   constrainedToSize:CGSizeMake(newFrame.size.width, 1000.0f)];
	newFrame.size.height = textSize.height;
	_tweetLabel.frame = newFrame;
	
	newFrame.size = _lineView.image.size;
	newFrame.size.width = screenWidth;
	newFrame.origin.x = floorf((screenWidth - newFrame.size.width) / 2);
	newFrame.origin.y = self.frame.size.height - newFrame.size.height;
	_lineView.frame = newFrame;
}


-(void) setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
